package br.com.nrti.still;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Spinner;
import android.widget.TextView;
import br.com.nrti.still.enumerator.EventoFim;
import br.com.nrti.still.enumerator.EventoIni;
import br.com.nrti.still.enumerator.ToqueFim;
import br.com.nrti.still.enumerator.ToqueIni;
import br.com.nrti.still.eventos.Alarme;
import br.com.nrti.still.eventos.Notificacoes;
import br.com.nrti.still.eventos.Toque;

import com.actionbarsherlock.app.SherlockFragment;

public class TabEventos_Acoes extends SherlockFragment {

	/**
	 * Controle de tela
	 */
	CheckBox cbRestaurarTermino;

	TextView tvIniToque;
	TextView tvFimToque;
	Spinner spIniToque;
	Spinner spFimToque;

	TextView tvIniAviao;
	TextView tvFimAviao;
	Spinner spIniAviao;
	Spinner spFimAviao;

	TextView tvIniWifi;
	TextView tvFimWifi;
	Spinner spIniWifi;
	Spinner spFimWifi;

	TextView tvIniDados;
	TextView tvFimDados;
	Spinner spIniDados;
	Spinner spFimDados;

	TextView tvIniBluetooth;
	TextView tvFimBluetooth;
	Spinner spIniBluetooth;
	Spinner spFimBluetooth;

	TextView tvIniAlarme;
	TextView tvFimAlarme;
	Spinner spIniAlarme;
	Spinner spFimAlarme;

	TextView tvIniCalendario;
	TextView tvFimCalendario;
	Spinner spIniCalendario;
	Spinner spFimCalendario;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		Toque.inicializar(TabEventos_Acoes.this.getSherlockActivity());
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.f_evento_acoes, container, false);

		cbRestaurarTermino = (CheckBox) view
				.findViewById(R.id.cbRestaurarFinal);

		tvIniToque = (TextView) view.findViewById(R.id.tvIniToque);
		tvFimToque = (TextView) view.findViewById(R.id.tvFimToque);
		spIniToque = (Spinner) view.findViewById(R.id.spIniToque);
		spFimToque = (Spinner) view.findViewById(R.id.spFimToque);

		tvIniAviao = (TextView) view.findViewById(R.id.tvIniAviao);
		tvFimAviao = (TextView) view.findViewById(R.id.tvFimAviao);
		spIniAviao = (Spinner) view.findViewById(R.id.spIniAviao);
		spFimAviao = (Spinner) view.findViewById(R.id.spFimAviao);

		tvIniWifi = (TextView) view.findViewById(R.id.tvIniWiFi);
		tvFimWifi = (TextView) view.findViewById(R.id.tvFimWiFi);
		spIniWifi = (Spinner) view.findViewById(R.id.spIniWiFi);
		spFimWifi = (Spinner) view.findViewById(R.id.spFimWiFi);

		tvIniDados = (TextView) view.findViewById(R.id.tvIniDados);
		tvFimDados = (TextView) view.findViewById(R.id.tvFimDados);
		spIniDados = (Spinner) view.findViewById(R.id.spIniDados);
		spFimDados = (Spinner) view.findViewById(R.id.spFimDados);

		tvIniBluetooth = (TextView) view.findViewById(R.id.tvIniBlue);
		tvFimBluetooth = (TextView) view.findViewById(R.id.tvFimBlue);
		spIniBluetooth = (Spinner) view.findViewById(R.id.spIniBlue);
		spFimBluetooth = (Spinner) view.findViewById(R.id.spFimBlue);

		tvIniAlarme = (TextView) view.findViewById(R.id.tvIniAlarme);
		tvFimAlarme = (TextView) view.findViewById(R.id.tvFimAlarme);
		spIniAlarme = (Spinner) view.findViewById(R.id.spIniAlarme);
		spFimAlarme = (Spinner) view.findViewById(R.id.spFimAlarme);

		tvIniCalendario = (TextView) view.findViewById(R.id.tvIniCalend);
		tvFimCalendario = (TextView) view.findViewById(R.id.tvFimCalend);
		spIniCalendario = (Spinner) view.findViewById(R.id.spIniCalend);
		spFimCalendario = (Spinner) view.findViewById(R.id.spFimCalend);

		cbRestaurarTermino
				.setOnCheckedChangeListener(new OnCheckedChangeListener() {
					@Override
					public void onCheckedChanged(CompoundButton arg0,
							boolean checked) {
						ativaModoRestauracao(!checked);
					}
				});

		populateSpinners();		
		return view;
	}

	public void populateSpinners() {
		spIniToque.setAdapter(new ArrayAdapter<ToqueIni>(this
				.getSherlockActivity(), android.R.layout.simple_spinner_item,
				ToqueIni.values()));
		spFimToque.setAdapter(new ArrayAdapter<ToqueFim>(this
				.getSherlockActivity(), android.R.layout.simple_spinner_item,
				ToqueFim.values()));
		
		spIniAviao.setAdapter(new ArrayAdapter<EventoIni>(this
				.getSherlockActivity(), android.R.layout.simple_spinner_item,
				EventoIni.values()));
		spFimAviao.setAdapter(new ArrayAdapter<EventoFim>(this
				.getSherlockActivity(), android.R.layout.simple_spinner_item,
				EventoFim.values()));
		
		spIniWifi.setAdapter(new ArrayAdapter<EventoIni>(this
				.getSherlockActivity(), android.R.layout.simple_spinner_item,
				EventoIni.values()));
		spFimWifi.setAdapter(new ArrayAdapter<EventoFim>(this
				.getSherlockActivity(), android.R.layout.simple_spinner_item,
				EventoFim.values()));
		
		spIniDados.setAdapter(new ArrayAdapter<EventoIni>(this
				.getSherlockActivity(), android.R.layout.simple_spinner_item,
				EventoIni.values()));
		spFimDados.setAdapter(new ArrayAdapter<EventoFim>(this
				.getSherlockActivity(), android.R.layout.simple_spinner_item,
				EventoFim.values()));
		
		spIniBluetooth.setAdapter(new ArrayAdapter<EventoIni>(this
				.getSherlockActivity(), android.R.layout.simple_spinner_item,
				EventoIni.values()));
		spFimBluetooth.setAdapter(new ArrayAdapter<EventoFim>(this
				.getSherlockActivity(), android.R.layout.simple_spinner_item,
				EventoFim.values()));
		
		spIniAlarme.setAdapter(new ArrayAdapter<EventoIni>(this
				.getSherlockActivity(), android.R.layout.simple_spinner_item,
				EventoIni.values()));
		spFimAlarme.setAdapter(new ArrayAdapter<EventoFim>(this
				.getSherlockActivity(), android.R.layout.simple_spinner_item,
				EventoFim.values()));
		
		spIniCalendario.setAdapter(new ArrayAdapter<EventoIni>(this
				.getSherlockActivity(), android.R.layout.simple_spinner_item,
				EventoIni.values()));
		spFimCalendario.setAdapter(new ArrayAdapter<EventoFim>(this
				.getSherlockActivity(), android.R.layout.simple_spinner_item,
				EventoFim.values()));
	}

	public void ativaModoRestauracao(boolean ativar) {
		int modo = ativar ? View.VISIBLE : View.GONE;

		tvIniToque.setVisibility(modo);
		tvFimToque.setVisibility(modo);
		spFimToque.setVisibility(modo);

		tvIniAviao.setVisibility(modo);
		tvFimAviao.setVisibility(modo);
		spFimAviao.setVisibility(modo);

		tvIniWifi.setVisibility(modo);
		tvFimWifi.setVisibility(modo);
		spFimWifi.setVisibility(modo);

		tvIniDados.setVisibility(modo);
		tvFimDados.setVisibility(modo);
		spFimDados.setVisibility(modo);

		tvIniBluetooth.setVisibility(modo);
		tvFimBluetooth.setVisibility(modo);
		spFimBluetooth.setVisibility(modo);

		tvIniAlarme.setVisibility(modo);
		tvFimAlarme.setVisibility(modo);
		spFimAlarme.setVisibility(modo);

		tvIniCalendario.setVisibility(modo);
		tvFimCalendario.setVisibility(modo);
		spFimCalendario.setVisibility(modo);
	}
}
